package cn.signalpha.modules.social.controller.api;

import cn.signalpha.common.constant.AppConstant;
import cn.signalpha.core.boot.ctrl.BaseController;
import cn.signalpha.core.mp.support.Condition;
import cn.signalpha.core.mp.support.Query;
import cn.signalpha.core.tool.api.R;
import cn.signalpha.core.tool.utils.BeanUtil;
import cn.signalpha.modules.base.dto.ComplaintDTO;
import cn.signalpha.modules.base.entity.Complaint;
import cn.signalpha.modules.base.service.ComplaintService;
import cn.signalpha.modules.base.vo.ComplaintVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.Map;

/**
 * 控制器
 *
 * @author signalpha
 */
@RestController
@AllArgsConstructor
@RequestMapping(AppConstant.APPLICATION_SOCIAL_NAME + "/wap/complaint")
@Api(value = "投诉", tags = "投诉")
public class ApiComplaintController extends BaseController {

	private final ComplaintService complaintService;

    @GetMapping("/page")
    @ApiOperation(value = "我的投诉", notes = "")
    public R<IPage<ComplaintVO>> page(@ApiIgnore @RequestParam Map<String, Object> params, Query query) {
        return R.data(complaintService.selectComplaintPage(Condition.getPage(query), params));
    }

	@GetMapping("/info")
	@ApiOperation(value = "详情", notes = "传入id")
	public R<Complaint> info(@ApiParam(value = "主键", required = true) @RequestParam Long id) {
		return R.data(complaintService.getById(id));
	}

	@PostMapping("/save")
	@ApiOperation(value = "提交", notes = "传入complaint")
	public R save(@Valid @RequestBody ComplaintDTO complaint) {
		return R.status(complaintService.save(BeanUtil.copy(complaint, Complaint.class)));
	}

}
